//
//  WTSocialShareView.m
//  66TV
//
//  Created by ben on 2016/12/8.
//  Copyright © 2016年 shifeng. All rights reserved.
//

#import "WTSocialShareView.h"
#import "WTCategories.h"

@interface WTSocialShareView ()
@property (nonatomic, strong) UILabel*  titleLabel;
@property (nonatomic, strong) UIButton* wechat_friendship_button;
@property (nonatomic, strong) UIButton* wechat_button;

@property (nonatomic, strong) UIButton* qq_button;
@property (nonatomic, strong) UIButton* qzone_button;

@property (nonatomic, strong) UIButton* sina_button;

@property (nonatomic, strong) UIView*   lineView;
@property (nonatomic, strong) UIButton* cancleButton;
@end


@implementation WTSocialShareView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = [UIColor whiteColor];
        self.layer.cornerRadius = 8;
        self.layer.masksToBounds = YES;
        [self setup];
    }
    return self;
}

#pragma mark -
- (void)setup{
    
    self.titleLabel = ({
        UILabel* label = [[UILabel alloc] init];
        label.numberOfLines = 1;
        label.textColor = [UIColor hexChangeFloat:@"969696"];
        label.font = [UIFont systemFontOfSize:12];
        label.text = @"分享至";
        [self addSubview:label];
        label;
    });
    
    self.wechat_friendship_button = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"share_wechat_friendship_icon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
        [button setTitle:@"朋友圈" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"646464"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:button];
        button;
    });
    
    self.wechat_button = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"share_wechat_icon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
        [button setTitle:@"微信好友" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"646464"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:button];
        button;
    });
    
    self.qq_button = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"share_qq_icon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
        [button setTitle:@"QQ" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"646464"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:button];
        button;
    });
    
    self.qzone_button = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"share_qzone_icon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
        [button setTitle:@"QQ空间" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"646464"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:button];
        button;
    });
    
    self.sina_button = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setImage:[UIImage imageNamed:@"share_sina_icon" inBundle:[NSBundle bundleForClass:[self class]] compatibleWithTraitCollection:nil] forState:UIControlStateNormal];
        [button setTitle:@"新浪微博" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"646464"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:10];
        [self addSubview:button];
        button;
    });
    
    self.lineView = ({
        UIView* view = [[UIView alloc] init];
        view.backgroundColor = [UIColor hexChangeFloat:@"969696"];
        [self addSubview:view];
        view;
    });
    
    self.cancleButton = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [button setTitle:@"取    消" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor hexChangeFloat:@"969696"] forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:12];
        [self addSubview:button];
        button;
    });
    
    [self layout];
}

#pragma mark -
- (void)layout{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.top.mas_equalTo(10);
    }];
    
    
    CGFloat width = CGRectGetWidth(self.bounds) - 40 - 32;
    
    [self.wechat_friendship_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(20);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(20);
        make.width.mas_equalTo(width/5);
    }];
    
    [self.wechat_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.wechat_friendship_button.mas_trailing).offset(8);
        make.top.mas_equalTo(self.wechat_friendship_button.mas_top);
        make.width.mas_equalTo(self.wechat_friendship_button.mas_width);
    }];
    
    [self.qq_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.wechat_button.mas_trailing).offset(8);
        make.top.mas_equalTo(self.wechat_friendship_button.mas_top);
        make.width.mas_equalTo(self.wechat_friendship_button.mas_width);
    }];
    
    [self.qzone_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.qq_button.mas_trailing).offset(8);
        make.top.mas_equalTo(self.wechat_friendship_button.mas_top);
        make.width.mas_equalTo(self.wechat_friendship_button.mas_width);
    }];
    
    [self.sina_button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.qzone_button.mas_trailing).offset(8);
        make.top.mas_equalTo(self.wechat_friendship_button.mas_top);
        make.width.mas_equalTo(self.wechat_friendship_button.mas_width);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.mas_equalTo(0);
        make.bottom.mas_equalTo(-35);
        make.height.mas_equalTo(1/[UIScreen mainScreen].scale);
    }];
    
    [self.cancleButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.and.bottom.mas_equalTo(0);
        make.height.mas_equalTo(35);
    }];
    
    
    
    self.wechat_friendship_button.lx_layoutType = LXButtonLayoutTypeImageTop;
    self.wechat_friendship_button.lx_subMargin = 10;
    
    self.wechat_button.lx_layoutType = LXButtonLayoutTypeImageTop;
    self.wechat_button.lx_subMargin = 10;
    
    self.qq_button.lx_layoutType = LXButtonLayoutTypeImageTop;
    self.qq_button.lx_subMargin = 10;
    
    self.qzone_button.lx_layoutType = LXButtonLayoutTypeImageTop;
    self.qzone_button.lx_subMargin = 10;
    
    self.sina_button.lx_layoutType = LXButtonLayoutTypeImageTop;
    self.sina_button.lx_subMargin = 10;
    
}

#pragma mark -
- (void)buttonPressed:(id)sender{
    
    NSInteger index = 0;
    if(sender == self.wechat_friendship_button){
        index = 0;
    }else if(sender == self.wechat_button){
        index = 1;
    }else if(sender == self.qq_button){
        index = 2;
    }else if(sender == self.qzone_button){
        index = 3;
    }else if(sender == self.sina_button){
        index = 4;
    }else if(sender == self.cancleButton){
        index = 5;
    }else {
        
    }
    if(self.block){
        self.block(index);
    }
}
@end
